package com.shwread.android.qysw.activity;

import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.shwread.android.qysw10000152.R;
import com.shwread.android.ui.dialog.CommonLoadingDialog;
import com.shwread.android.ui.dialog.ConfirmOrderInvoiceDialog;
import com.shwread.android.ui.dialog.DatePickerListener;
import com.shwread.http.ResultCode;
import com.shwread.http.base.Log;
import com.shwread.http.base.ObjectHttpResponseHandler;
import com.shwread.http.base.TextHttpResponseHandler;
import com.shwread.http.util.JSONUtil;
import com.shwread.http.util.Logger;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import logic.bean.ConfirmOrderInfo;
import logic.bean.ConfirmOrderResult;
import logic.bean.ConfirmOrdergoodsInfo;
import logic.bean.EnterpriseDictionary;
import logic.bean.ShoppingCart;
import logic.bean.UserAddressInfo;
import logic.constants.DefaultConsts;
import logic.dao.ShoppingCartDao;
import logic.util.MoneyUtil;
import logic.util.PicassoUtil;
import logic.util.ScreenUtil;
import logic.util.Utils;


/**
 * 确认订单
 * 
 * @author xuzhijun
 * @date 2015年3月20日 上午11:04:40
 */
public class ConfirmOrderActivity
        extends
        BaseBusinessActivity
        implements
        OnClickListener
{
	
	private final int                  DELIVER_TYPE_ALLDAY     = 1;
	private final int                  DELIVER_TYPE_WORKDAY    = 2;
	private final int                  DELIVER_TYPE_HOLIDAY    = 3;
	
	private final int                  INVOICE_TYPE_NONE       = 0;
	private final int                  INVOICE_TYPE_PERSONAL   = 1;
	private final int                  INVOICE_TYPE_ENTERPRISE = 2;
	
	public static final int            REMARK_REQUEST_CODE     = 1;
	public static final int            REMARK_FROM_CODE        = 2;
	public static final int            ADDRESS_REQUEST_CODE    = 3;
	public static final int            ADDRESS_FROM_CODE       = 4;
	public static final int            ARRESS_DELETE_SELECTED  = 5;
	private boolean                    addressOK               = false;
	
	private Context                    context;
	private TextView                   tvTitle;
	private Button                     btnHome;
	private Button                     btnBack;
	
	private ListView                   listView;                                                       //物品列表
	private LayoutInflater             inflater;
	private View                       topView;
	private View                       bottomView;
	private View                       orderNumberView;
	
	private RelativeLayout             chooseAddressLay;
	private View                       noAddressView;
	private View                       addressView;
	
	//	private OrderInfo          orderInfo;
	private UserAddressInfo            addressInfo;
	private List<ShoppingCart>         goodsCartList;
	private List<ShoppingCart>         goodsCartErrorList;
	
	private TextView                   tvAddressName;                                                  //收货地址的姓名
	private TextView                   tvAddressPhone;                                                 //收货地址的电话
	private TextView                   tvAdress;                                                       //收货地址
	                                                                                                    
	private GoodsAdapter               adapter;
	
	private RelativeLayout             remarkLay;
	private String                     remarkString;
	
	private TextView                   tvNum;
	
	//配送时间
	private TextView                   tvDeliverChoose;
	private ImageView                  ivDeliverChoose;
	private Button                     btnDeliverTimeAllDay;                                           //全天
	private Button                     btnDeliverTimeWorkDay;                                          //工作日
	private Button                     btnDeliverTimeHoliDay;                                          //假日
	private int                        delivelyTimeType        = 1;                                    //1==全天；2==工作日；3==假日，默认工作日
	private int                        provinceID;
	
	private RelativeLayout             deliverTimeLayParent;                                           //配送时间_头
	private LinearLayout               deliverTimeLayChildren;
	
	//开具发票
	private boolean                    isPsersonal             = false;
	private boolean                    isEnterprise            = false;
	private int                        invoiceType             = INVOICE_TYPE_NONE;
	
	private RelativeLayout             invoiceLayParent;                                               //发票点击_头
	private LinearLayout               invoiceLayChildren, invoiceLayContents, invoiceLayEdits;
	
	private TextView                   tvDeliverFee;
	private TextView                   tvInvoiceChoose, tvInvoiceTypeChoose;
	private ImageView                  ivInvoiceChoose;
	private Button                     btnInvoicePersonal;                                             //个人发票
	private Button                     btnInvoiceEnterprise;                                           //企业发票
	private EditText                   edtInvoiceName;                                                 //发票名
	private EditText                   edtInvoiceNumber;                                               //税号
	private Button                     confirmBtn;
	private TextView                   tvInvoiceType;
	private ImageView                  ivInvoiceMoreType;
	
	private TextView                   tvTotalPrice;                                                   //总价tv
	private int                        totalPrice              = 0;                                    //总价
	                                                                                                    
	private Button                     btnNoAddress;
	private Intent                     addressIntent;
	private String                     fromType;
	private CommonLoadingDialog        loadingDialog;
	
	private int                        fee                     = -1;                                   //快递费
	private int                        currFee                 = -1;                                   //当前快递费
	private ShoppingCartDao            dao;
	private boolean                    couponOnly              = true;
	private boolean                    onlyOne                 = false;
	
	private List<EnterpriseDictionary> listType                = new ArrayList<EnterpriseDictionary>();
	private EnterpriseDictionary       currType                = new EnterpriseDictionary();
	private int                        isClose                 = 0;
	
	@Override
	public Handler getUIHandler() {
		return null;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.confirm_order);
		context = this;
		dao = ShoppingCartDao.getInstance(context);
		initView();
		initData();
		setListener();
	}
	
	private void initView() {
		//Title
		tvTitle = (TextView) findViewById(R.id.common_header_name);
		tvTitle.setText(getResources().getString(R.string.confirm_order_title));
		btnHome = (Button) findViewById(R.id.common_header_home);
		btnHome.setVisibility(View.VISIBLE);
		btnBack = (Button) findViewById(R.id.common_header_back);
		btnBack.setVisibility(View.VISIBLE);
		
		listView = (ListView) findViewById(R.id.confirm_order_list);
		inflater = LayoutInflater.from(ConfirmOrderActivity.this);
		
		bottomView = inflater.inflate(R.layout.confirm_order_bottom, null);//
		orderNumberView = inflater.inflate(R.layout.goods_detail_item_top, null);
		tvNum = (TextView) orderNumberView.findViewById(R.id.goods_detail_item_top_order_number);
		tvNum.setText("商品详情");
		tvNum.setVisibility(View.VISIBLE);
		noAddressView = inflater.inflate(R.layout.confirm_order_top_add, null);
		btnNoAddress = (Button) noAddressView.findViewById(R.id.address_info_add_btn);
		
		addressView = inflater.inflate(R.layout.common_order_address, null);
		tvAddressName = (TextView) addressView.findViewById(R.id.common_order_address_name_tv);
		tvAddressPhone = (TextView) addressView.findViewById(R.id.common_order_address_phone_tv);
		tvAdress = (TextView) addressView.findViewById(R.id.common_order_address_tv);
		
		remarkLay = (RelativeLayout) bottomView.findViewById(R.id.confirm_order_bottom_remark_lay);
		
		chooseAddressLay = (RelativeLayout) addressView.findViewById(R.id.common_order_address_lay);
		
		//配送时间finView
		deliverTimeLayParent = (RelativeLayout) bottomView.findViewById(R.id.confirm_order_bottom_deliver_lay);
		deliverTimeLayChildren = (LinearLayout) bottomView.findViewById(R.id.confirm_order_bottom_deliver_detail_lay);
		deliverTimeLayChildren.setVisibility(View.GONE);
		btnDeliverTimeAllDay = (Button) bottomView.findViewById(R.id.confirm_order_bottom_allday_btn);
		btnDeliverTimeWorkDay = (Button) bottomView.findViewById(R.id.confirm_order_bottom_workday_btn);
		
		/** 同一控件不同字体 */
		String workDay = getResources().getString(R.string.confirm_order_bottom_workday);
		int start = workDay.indexOf("（");
		int end = workDay.indexOf("）") + 1;
		Spannable workDayText = new SpannableString(workDay);
		workDayText.setSpan(new AbsoluteSizeSpan(ScreenUtil.dip2px(16)), 0, start, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
		workDayText.setSpan(new ForegroundColorSpan(Color.parseColor("#323232")), 0, start, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
		workDayText.setSpan(new AbsoluteSizeSpan(ScreenUtil.dip2px(14)), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
		workDayText.setSpan(new ForegroundColorSpan(Color.parseColor("#676767")), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
		btnDeliverTimeWorkDay.setText(workDayText);
		
		btnDeliverTimeHoliDay = (Button) bottomView.findViewById(R.id.confirm_order_bottom_holiday_btn);
		
		/** 同一控件不同字体 */
		String holiDay = getResources().getString(R.string.confirm_order_bottom_holiday);
		start = holiDay.indexOf("（");
		end = holiDay.indexOf("）") + 1;
		Spannable holiDayText = new SpannableString(holiDay);
		holiDayText.setSpan(new AbsoluteSizeSpan(ScreenUtil.dip2px(16)), 0, start, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
		holiDayText.setSpan(new ForegroundColorSpan(Color.parseColor("#323232")), 0, start, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
		holiDayText.setSpan(new AbsoluteSizeSpan(ScreenUtil.dip2px(14)), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
		holiDayText.setSpan(new ForegroundColorSpan(Color.parseColor("#676767")), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
		btnDeliverTimeHoliDay.setText(holiDayText);
		
		tvDeliverChoose = (TextView) bottomView.findViewById(R.id.confirm_order_bottom_deliver_choose_tv);
		ivDeliverChoose = (ImageView) bottomView.findViewById(R.id.confirm_order_bottom_deliver_more);
		setDeliverTime(DELIVER_TYPE_ALLDAY);
		//发票finView
		invoiceLayParent = (RelativeLayout) bottomView.findViewById(R.id.confirm_order_bottom_invoice_lay);
		invoiceLayChildren = (LinearLayout) bottomView.findViewById(R.id.confirm_order_bottom_invoice_detail_lay);
		invoiceLayChildren.setVisibility(View.GONE);
		invoiceLayContents = (LinearLayout) bottomView.findViewById(R.id.confirm_order_bottom_invoice_content);
		invoiceLayContents.setVisibility(View.GONE);
		btnInvoicePersonal = (Button) bottomView.findViewById(R.id.confirm_order_bottom_invoice_personal_btn);
		btnInvoiceEnterprise = (Button) bottomView.findViewById(R.id.confirm_order_bottom_invoice_enterprise_btn);
		invoiceLayEdits = (LinearLayout) bottomView.findViewById(R.id.confirm_order_bottom_invoice_edt);
		invoiceLayEdits.setVisibility(View.GONE);
		edtInvoiceName = (EditText) bottomView.findViewById(R.id.confirm_order_bottom_invoice_name_edt);
		edtInvoiceNumber = (EditText) bottomView.findViewById(R.id.confirm_order_bottom_invoice_number_edt);
		tvInvoiceChoose = (TextView) bottomView.findViewById(R.id.confirm_order_bottom_invoice_choose_tv);
		tvInvoiceTypeChoose = (TextView) bottomView.findViewById(R.id.confirm_order_bottom_invoice_type_tv);
		ivInvoiceChoose = (ImageView) bottomView.findViewById(R.id.confirm_order_bottom_invoice_more);
		tvDeliverFee = (TextView) bottomView.findViewById(R.id.confirm_order_bottom_deliver_tv);
		
		tvTotalPrice = (TextView) findViewById(R.id.total_price_bottom_total_price_tv);
		confirmBtn = (Button) findViewById(R.id.total_price_bottom_buy_tv);
		tvInvoiceType = (TextView) bottomView.findViewById(R.id.confirm_order_bottom_invoice_type);
		ivInvoiceMoreType = (ImageView) bottomView.findViewById(R.id.confirm_order_bottom_invoice_moretype);
		
		loadingDialog = new CommonLoadingDialog(context);
	}
	
	private void initData() {
		adapter = new GoodsAdapter();
		InitGoodsList();
		initEnterpriseDictionary();
	}
	
	public void initEnterpriseDictionary() {
		loadingDialog.show();
		ActionHelp.qryEnterpriseDictionary(context, 1001, new QryEnterpriseDictionaryHandler());
	}
	
	private boolean wantInvoice() {
		if (isEnterprise || isPsersonal) return true;
		return false;
	}
	
	private void setListener() {
		btnHome.setOnClickListener(this);
		btnBack.setOnClickListener(this);
		btnDeliverTimeAllDay.setOnClickListener(this);
		btnDeliverTimeWorkDay.setOnClickListener(this);
		btnDeliverTimeHoliDay.setOnClickListener(this);
		deliverTimeLayParent.setOnClickListener(this);
		invoiceLayParent.setOnClickListener(this);
		invoiceLayContents.setOnClickListener(this);
		btnInvoicePersonal.setOnClickListener(this);
		btnInvoiceEnterprise.setOnClickListener(this);
		remarkLay.setOnClickListener(this);
		chooseAddressLay.setOnClickListener(this);
		btnNoAddress.setOnClickListener(this);
		confirmBtn.setOnClickListener(this);
		//		listView.setOnItemClickListener(new OnItemClickListener()
		//		{
		//			
		//			@Override
		//			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		//				
		//				if (!(position < listView.getHeaderViewsCount() && position > goodsCartList.size() + listView.getHeaderViewsCount() - 1))
		//				{
		//					position = position - listView.getHeaderViewsCount();
		//					Intent intent = new Intent(ConfirmOrderActivity.this, NewGoodsMainActivity.class);
		//					long goodsId = goodsCartList.get(position).goodsId;
		//					String detailUrl = goodsCartList.get(position).goodsDetailUrl;
		//					intent.putExtra(DefaultConsts.GOODS_ID_TO_WAP, goodsId);
		//					intent.putExtra(DefaultConsts.GOODS_URL_TO_WAP, detailUrl);
		//					startActivity(intent);
		//				}
		//				
		//			}
		//		});
	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.common_header_home:
				//				Utils.ToastShow(ConfirmOrderActivity.this, "点击了返回主页");
				//				startActivity(new Intent(ConfirmOrderActivity.this, MainActivity.class));
				BaseSimpleActivity.gotoMainActivity();
				break;
			case R.id.common_header_back:
				ConfirmOrderActivity.this.finish();
				break;
			case R.id.confirm_order_bottom_deliver_lay:
				clickDeliver();
				break;
			case R.id.common_order_address_lay:
				addressIntent = new Intent(ConfirmOrderActivity.this, AddressInfoListActivity.class);
				addressIntent.putExtra(DefaultConsts.FROM_TYPE, ADDRESS_REQUEST_CODE);
				startActivityForResult(addressIntent, ADDRESS_REQUEST_CODE);
				break;
			case R.id.confirm_order_bottom_allday_btn:
				setDeliverTime(DELIVER_TYPE_ALLDAY);
				break;
			case R.id.confirm_order_bottom_workday_btn:
				setDeliverTime(DELIVER_TYPE_WORKDAY);
				break;
			case R.id.confirm_order_bottom_holiday_btn:
				setDeliverTime(DELIVER_TYPE_HOLIDAY);
				break;
			case R.id.confirm_order_bottom_invoice_lay:
				clickInvoice();
				break;
			case R.id.confirm_order_bottom_invoice_content:
				if (listType != null && listType.size() > 1)
				{
					clickInvoiceContent();
				}
				break;
			case R.id.confirm_order_bottom_invoice_personal_btn:
				clickInvoicePersonal();
				break;
			case R.id.confirm_order_bottom_invoice_enterprise_btn:
				clickInvoiceEnterprise();
				break;
			case R.id.confirm_order_bottom_remark_lay:
				Intent intent = new Intent(ConfirmOrderActivity.this, RemarkActivity.class);
				if (remarkString == null)
				{
					remarkString = new String();
				}
				intent.putExtra(DefaultConsts.REMARK, remarkString);
				startActivityForResult(intent, REMARK_REQUEST_CODE);
				break;
			case R.id.total_price_bottom_buy_tv:
				
				ConfirmOrderInfo confirmOrderInfo;
				Gson gson = new Gson();
				
				List<ConfirmOrdergoodsInfo> goodsList = new ArrayList<ConfirmOrdergoodsInfo>();
				for (ShoppingCart info : goodsCartList)
				{
					ConfirmOrdergoodsInfo good = new ConfirmOrdergoodsInfo();
					good.setBuyNum(info.count);
					good.setCoverUrl(info.picUrl);
					good.setGoodsId(info.goodsId);
					good.setSkuId(info.skuId);
					good.setTitle(info.title);
					good.setActivityId(info.activityId);
					good.setShoppingCartId(info.id);
					//TODO
					Map<String, String> skuProp = new HashMap<String, String>();
					if (!Utils.isEmpty(info.skuPropDetail))
					{
						for (String s : info.skuPropDetail.split(","))
						{
							String[] prop = s.split(":");
							skuProp.put(prop[0], prop[1]);
						}
						good.setSkuProp(skuProp);
					}
					goodsList.add(good);
				}
				
				//				confirmOrderInfo = new ConfirmOrderInfo(delivelyTimeType, 1000, addressInfo, goodsList);
				if (remarkString == null)
				{
					remarkString = new String();
				}
				if (!onlyOne && wantInvoice() && (currType == null || Utils.isEmpty(currType.getName())))
				{
					Utils.ToastShow(context, "请选择发票内容");
					return;
				}
				
				confirmOrderInfo = new ConfirmOrderInfo(remarkString, delivelyTimeType, invoiceType, edtInvoiceName.getText().toString(), edtInvoiceNumber.getText().toString(), currType.getName(), currFee, addressInfo, goodsList);
				
				String confirmOrderString;
				if (!couponOnly && fee <= -1)
				{
					Utils.ToastShow(context, "快递费用获取失败");
					return;
				}
				if (couponOnly && wantInvoice() && fee <= -1)
				{
					Utils.ToastShow(context, "快递费用获取失败");
					return;
				}
				
				switch (invoiceType) {
					case INVOICE_TYPE_NONE:
						confirmOrderString = gson.toJson(confirmOrderInfo);
						loadingDialog.show();
						ActionHelp.confirmOrder(context, confirmOrderString, new ConfirmOrderHandler());
						System.out.println("xxxxxxxxxxxxxxxxxxx" + confirmOrderString);
						break;
					case INVOICE_TYPE_PERSONAL:
						
						if (edtInvoiceName.getText().toString().length() < 1)
						{
							Utils.ToastShow(context, "请填写个人账户名");
							return;
						}
						else
						{
							//							Utils.ToastShow(context, "提交订单");
							loadingDialog.show();
							confirmOrderInfo.setInvoiceAccount(edtInvoiceName.getText().toString());
							confirmOrderString = gson.toJson(confirmOrderInfo);
							ActionHelp.confirmOrder(context, confirmOrderString, new ConfirmOrderHandler());
						}
						
						break;
					case INVOICE_TYPE_ENTERPRISE:
						if (edtInvoiceName.getText().toString().length() < 1)
						{
							Utils.ToastShow(context, "请填写企业账户名");
							return;
						}
						else if (edtInvoiceNumber.getText().toString().length() < 1)
						{
							Utils.ToastShow(context, "请填写企业税号");
							return;
						}
						else
						{
							loadingDialog.show();
							//							Utils.ToastShow(context, "提交订单");
							confirmOrderInfo.setInvoiceAccount(edtInvoiceName.getText().toString());
							confirmOrderInfo.setInvoiceCode(edtInvoiceNumber.getText().toString());
							confirmOrderString = gson.toJson(confirmOrderInfo);
							ActionHelp.confirmOrder(context, confirmOrderString, new ConfirmOrderHandler());
						}
						break;
				}
				break;
			case R.id.address_info_add_btn:
				//				addressIntent = new Intent(ConfirmOrderActivity.this, AddressInfoListActivity.class);
				//				addressIntent.putExtra(DefaultConsts.FROM_TYPE, ADDRESS_REQUEST_CODE);
				//				startActivityForResult(addressIntent, ADDRESS_REQUEST_CODE);
				
				Intent addressInfoEditIntent = new Intent(ConfirmOrderActivity.this, AddressInfoEditActivity.class);
				addressInfoEditIntent.putExtra(DefaultConsts.EDIT_ADDRESS_FROM_TYPE, DefaultConsts.EDIT_ADDRESS_ADD_TAG);
				addressInfoEditIntent.putExtra(DefaultConsts.EDIT_ADDRESS_FROM_CONFIEM_ORDER, DefaultConsts.EDIT_ADDRESS_DEFAULT_ADD_TAG);
				startActivityForResult(addressInfoEditIntent, DefaultConsts.EDIT_ADDRESS_NO_ADDRESS_ORDER);
				
				break;
			default:
				break;
		}
	}
	
	private void clickInvoiceContent() {
		String location = tvInvoiceType.getText().toString().trim();
		new ConfirmOrderInvoiceDialog(this, listType, location, new ConfirmOrderInvoiceListener()).show();
	}
	
	private class ConfirmOrderInvoiceListener
	        implements
	        DatePickerListener
	{
		@Override
		public void onSelect(String value) {
			tvInvoiceType.setText(value);
			tvInvoiceTypeChoose.setText(value + ",");
			for (int i = 0; i < listType.size(); i++)
			{
				if (value.equals(listType.get(i).getName()))
				{
					currType = listType.get(i);
					break;
				}
			}
		}
	}
	
	class ConfirmOrderHandler
	        extends
	        ObjectHttpResponseHandler<ConfirmOrderResult>
	{
		
		@Override
		public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
			Logger.e(throwable);
			Logger.i(responseString);
			loadingDialog.dismiss();
			switch (statusCode) {
				case ResultCode.E_6004:
					try
					{
						String resultString = JSONUtil.getString(responseString);
						
						if (fromType.equals(DefaultConsts.CONFIRM_ORDER_FROM_SHOPPING_CART))
						{
							
							Gson gson = new Gson();
							Map<String, Integer> resultMap = gson.fromJson(resultString, new TypeToken<Map<String, Integer>>()
							{
							}.getType());
							for (Entry<String, Integer> entry : resultMap.entrySet())
							{
								for (ShoppingCart shoppingCart : goodsCartList)
								{
									if (shoppingCart.id == Integer.parseInt(entry.getKey()))
									{
										shoppingCart.errorCode = String.valueOf(entry.getValue());//添加错误码  要会写数据库
										shoppingCart.ordersStatus = ShoppingCart.ORDERSTATUS_FAIL;
										switch (entry.getValue()) {//添加错误信息
											case ResultCode.E_6001:
												shoppingCart.errorMsg = "活动结束";
												break;
											case ResultCode.E_6002:
												shoppingCart.errorMsg = "库存不足";
												break;
											case ResultCode.E_6003:
												shoppingCart.errorMsg = "商品下架";
												break;
										}
										goodsCartErrorList.add(shoppingCart);
										dao.update(shoppingCart);//更新数据库
									}
								}
							}
							goodsCartList.removeAll(goodsCartErrorList);
							
							List<ShoppingCart> allData = new ArrayList<ShoppingCart>();
							allData.addAll(goodsCartList);
							allData.addAll(goodsCartErrorList);
							adapter.setData(allData);
							adapter.notifyDataSetChanged();
							if (goodsCartList.size() > 0)
							{
								confirmBtn.setText("继续提交");
							}
							//							Intent oldIntent = getIntent();
							//							oldIntent.putExtra(ShoppingCartActivity.SUBMIT_ERROR_MESSAGE, resultString);
							//							setResult(ShoppingCartActivity.SHOPPING_CART_RESULT_CODE_SUBMIT_ERROR_6004, oldIntent);
							//							ConfirmOrderActivity.this.finish();
						}
						else
						{
							Gson gson = new Gson();
							Map<Long, Integer> resultMap = gson.fromJson(resultString, new TypeToken<Map<Long, Integer>>()
							{
							}.getType());
							for (Entry<Long, Integer> entry : resultMap.entrySet())
							{
								switch (entry.getValue()) {
									case ResultCode.E_6001:
										goodsCartList.get(0).ordersStatus = ShoppingCart.ORDERSTATUS_FAIL;
										goodsCartList.get(0).errorCode = String.valueOf(ResultCode.E_6001);
										goodsCartList.get(0).errorMsg = "活动结束";
										break;
									case ResultCode.E_6002:
										goodsCartList.get(0).ordersStatus = ShoppingCart.ORDERSTATUS_FAIL;
										goodsCartList.get(0).errorCode = String.valueOf(ResultCode.E_6002);
										goodsCartList.get(0).errorMsg = "库存不足";
										break;
									case ResultCode.E_6003:
										goodsCartList.get(0).ordersStatus = ShoppingCart.ORDERSTATUS_FAIL;
										goodsCartList.get(0).errorCode = String.valueOf(ResultCode.E_6003);
										goodsCartList.get(0).errorMsg = "商品下架";
										break;
								}
							}
							goodsCartErrorList.add(goodsCartList.get(0));
							goodsCartList.removeAll(goodsCartErrorList);
							List<ShoppingCart> allData = new ArrayList<ShoppingCart>();
							allData.addAll(goodsCartList);
							allData.addAll(goodsCartErrorList);
							adapter.setData(allData);
							adapter.notifyDataSetChanged();
						}
					}
					catch (JSONException e)
					{
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					calMoney();
					setBtn();
					
					break;
				case 6005:
					Utils.showToast(context, "物流公司不存在");
					break;
				case 6006:
					Utils.showToast(context, "提交订单时无法获取到该地区的运费");
					break;
				case 9999:
					Utils.showToast(context, "订单提交失败");
					break;
				default:
					break;
			}
			
			//				
			//				String[] results = resultString.split(",");
			//				
			//				for (String string : results)
			//				{
			//					code = string.split(":")[1];
			//					
			//					switch (Integer.parseInt(code)) {
			//						case 6001:
			//							Utils.ToastShow(context, "活动结束" + statusCode);
			//							break;
			//						case 6002:
			//							Utils.ToastShow(context, "库存不足" + statusCode);
			//							break;
			//						case 6003:
			//							Utils.ToastShow(context, "商品已下架" + statusCode);
			//							break;
			//					}
			//					
			//				}
			
			//			Utils.ToastShow(context, "订单提交失败错误码" + statusCode);
		}
		
		@Override
		public void onSuccess(int statusCode, Header[] headers, ConfirmOrderResult object, String responseString) {
			Logger.d(responseString);
			switch (statusCode) {
				case 1000:
					loadingDialog.dismiss();
					Utils.ToastShow(context, "提交成功");
					if (null != object)
					{
						//跳转到支付页面
						Intent orderPayIntent = new Intent(ConfirmOrderActivity.this, OrderPayActivity.class);
						orderPayIntent.putExtra(DefaultConsts.ORDER_DETAIL_ORDER_ORDER_INTRO, goodsCartList.get(0).intro);
						orderPayIntent.putExtra(DefaultConsts.ORDER_DETAIL_ORDER_ORDER_TITLE, goodsCartList.get(0).title);
						orderPayIntent.putExtra(DefaultConsts.ORDER_DETAIL_ORDER_PAY_MONEY, object.actualMoney);
						orderPayIntent.putExtra(DefaultConsts.ORDER_DETAIL_ORDER_SERIAL, object.orderSerial);
						
						if (fromType.equals(DefaultConsts.CONFIRM_ORDER_FROM_SHOPPING_CART))
						{
							Intent oldIntent = getIntent();
							ShoppingCartDao dao = ShoppingCartDao.getInstance(context);
							dao.deleteAll(ActionHelp.getAccount());
							oldIntent.putExtra(ShoppingCartActivity.SUBMIT_STATE, ShoppingCartActivity.SUBMIT_OK);
							setResult(ShoppingCartActivity.SHOPPING_CART_RESULT_CODE, oldIntent);
						}
						startActivity(orderPayIntent);
						ConfirmOrderActivity.this.finish();
					}
					
					break;
				
				default:
					//					Utils.ToastShow(context, "订单提交失败错误码" + statusCode);
					break;
			}
		}
		
		@Override
		public Type getType() {
			return new TypeToken<ConfirmOrderResult>()
			{
			}.getType();
		}
	}
	
	class QryEnterpriseDictionaryHandler
	        extends
	        ObjectHttpResponseHandler<List<EnterpriseDictionary>>
	{
		
		@Override
		public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
			Logger.e(throwable);
			Logger.i(responseString);
		}
		
		@Override
		public void onSuccess(int statusCode, Header[] headers, List<EnterpriseDictionary> object, String responseString) {
			Log.i(responseString);
			InitAddressInfo();
			if (object != null)
			{
				if (listType.size() > 0) listType.clear();
				listType.addAll(object);
			}
			if (!onlyOne && listType.size() == 1)
			{
				tvInvoiceType.setText(listType.get(0).getName());
				currType = listType.get(0);
				ivInvoiceMoreType.setVisibility(View.INVISIBLE);
			}
			else
			{
				ivInvoiceMoreType.setVisibility(View.VISIBLE);
			}
		}
		
		@Override
		public Type getType() {
			return new TypeToken<List<EnterpriseDictionary>>()
			{
			}.getType();
		}
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		
		if (requestCode == ConfirmOrderActivity.REMARK_REQUEST_CODE && resultCode == ConfirmOrderActivity.REMARK_FROM_CODE)
		{
			remarkString = data.getExtras().getString(DefaultConsts.REMARK);
			Utils.ToastShow(context, remarkString);
		}
		else if (requestCode == ADDRESS_REQUEST_CODE && resultCode == ADDRESS_FROM_CODE)
		{
			addressInfo = (UserAddressInfo) data.getExtras().get(DefaultConsts.ADDRESS_LIST);
			changeAddress(addressInfo);
			
		}
		else if ((requestCode == DefaultConsts.EDIT_ADDRESS_NO_ADDRESS_ORDER && resultCode == DefaultConsts.EDIT_ADDRESS_ADD_OK_N) || (requestCode == ConfirmOrderActivity.ADDRESS_REQUEST_CODE && resultCode == ConfirmOrderActivity.ARRESS_DELETE_SELECTED))
		{
			InitOnResultAddressInfo();
		}
		
	}
	
	private void changeAddress(UserAddressInfo addressInfo) {
		listView.removeHeaderView(topView);
		listView.removeHeaderView(orderNumberView);
		tvAddressName.setText(addressInfo.getName());
		tvAddressPhone.setText(addressInfo.getPhone());
		tvAdress.setText("收货地址：" + addressInfo.getProvinceName() + addressInfo.getCityName() + addressInfo.getAreaName() + addressInfo.getDetailAddress());
		topView = addressView;
		listView.addHeaderView(topView, null, false);
		listView.addHeaderView(orderNumberView);
		InitDiliverMoney();
	};
	
	private void InitGoodsList() {
		
		//TODO 需要判断是从哪里进来  购物车:取数据库里所有数据, 商品详情:单样商品
		
		Intent intent = getIntent();
		fromType = intent.getExtras().getString(DefaultConsts.FROM_TYPE);
		if (fromType.equals(DefaultConsts.CONFIRM_ORDER_FROM_GOODS_MAIN))
		{
			goodsCartList = new ArrayList<ShoppingCart>();
			goodsCartList.add((ShoppingCart) intent.getExtras().get(DefaultConsts.CONFIRM_ORDER_GOODS));
			calMoney();
		}
		else if (fromType.equals(DefaultConsts.CONFIRM_ORDER_FROM_SHOPPING_CART))
		{
			goodsCartList = dao.queryByAccount(ActionHelp.getAccount());
			goodsCartList.removeAll(dao.queryByFail(ActionHelp.getAccount()));
			calMoney();
		}
		if (goodsCartList.size() == 1) onlyOne = true;
		goodsCartErrorList = new ArrayList<ShoppingCart>();
		adapter.setData(goodsCartList);
		
		for (int i = 0; i < goodsCartList.size(); i++)
		{
			if (goodsCartList.get(i).goodsType == 0)
			{
				couponOnly = false;
				break;
			}
		}
	}
	
	private void calMoney() {
		totalPrice = 0;
		for (ShoppingCart goods : goodsCartList)
		{
			int price;
			price = (goods.salePrice - goods.freeMoney) * goods.count;
			totalPrice = totalPrice + price;
		}
		tvTotalPrice.setText(" ¥" + Utils.getMoneyFormat(MoneyUtil.divide(totalPrice, 100)));
	}
	
	private void InitAddressInfo() {
		ActionHelp.qryUserDeliveryAddress(context, true, new DefaultAddressHandler());
	}
	
	private class DefaultAddressHandler
	        extends
	        ObjectHttpResponseHandler<List<UserAddressInfo>>
	{
		
		@Override
		public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
			loadingDialog.dismiss();
			addressOK = true;
			if (statusCode == 200)
			{
				try
				{
					JSONObject jsonObject = new JSONObject(responseString);
					JSONArray array = jsonObject.getJSONArray("returnObject");
					if (array == null || array.length() == 0)
					{
						topView = noAddressView;
						setBtn();
						setContentView();
					}
				}
				catch (JSONException e)
				{
					Utils.ToastShow(context, "解析错误");
				}
			}
			else if (statusCode < 1000)
			{
				Utils.ToastShow(context, "网络错误");
			}
			else
			{
				Utils.ToastShow(context, "请求出错");
			}
		}
		
		@Override
		public void onSuccess(int statusCode, Header[] headers, List<UserAddressInfo> object, String responseString) {
			addressInfo = object.get(0);
			addressOK = true;
			topView = addressView;
			tvAddressName.setText(addressInfo.getName());
			tvAddressPhone.setText(addressInfo.getPhone());
			tvAdress.setText("收货地址：" + addressInfo.getProvinceName() + addressInfo.getCityName() + addressInfo.getAreaName() + addressInfo.getDetailAddress());
			provinceID = addressInfo.getProviceId();
			System.out.println(provinceID + "");
			InitDiliverMoney();
			setBtn();
			setContentView();
			loadingDialog.dismiss();
		}
		
		@Override
		public Type getType() {
			return new TypeToken<List<UserAddressInfo>>()
			{
			}.getType();
		}
		
	}
	
	private void InitDiliverMoney() {
		if (addressInfo != null || addressInfo.getProviceId() != provinceID)
		{
			loadingDialog.show();
			ActionHelp.qryExpressFeeByProviceId(context, addressInfo.getProviceId(), new EnpressFeeHandler());
		}
		
	}
	
	class EnpressFeeHandler
	        extends
	        TextHttpResponseHandler
	{
		
		@Override
		public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
			if (addressOK)
			{
				loadingDialog.dismiss();
			}
			fee = -1;
			setDeliverFee();
			setBtn();
		}
		
		@Override
		public void onSuccess(int statusCode, Header[] headers, String responseString) {
			if (addressOK)
			{
				loadingDialog.dismiss();
			}
			try
			{
				fee = new JSONObject(responseString).getJSONObject("returnObject").getInt("fee");
				setDeliverFee();
			}
			catch (JSONException e)
			{
				e.printStackTrace();
			}
			setBtn();
		}
	}
	
	private void setContentView() {
		listView.addFooterView(bottomView);
		listView.addHeaderView(topView);
		listView.addHeaderView(orderNumberView);
		listView.setAdapter(adapter);
	}
	
	/**
	 * 判断是否可以提交
	 * 
	 * @return
	 */
	private void setBtn() {
		int padding = confirmBtn.getPaddingLeft();
		if (couponOnly && !wantInvoice())
		{
			confirmBtn.setBackgroundResource(R.drawable.button_make_order);
			confirmBtn.setPadding(padding, 0, padding, 0);
			confirmBtn.setClickable(true);
			tvTotalPrice.setText(" ¥" + Utils.getMoneyFormat(MoneyUtil.divide(totalPrice, 100)));
			return;
		}
		if (addressInfo != null && goodsCartList.size() > 0 && currFee > -1)
		{
			confirmBtn.setBackgroundResource(R.drawable.button_make_order);
			confirmBtn.setPadding(padding, 0, padding, 0);
			confirmBtn.setClickable(true);
			tvTotalPrice.setText(" ¥" + Utils.getMoneyFormat(MoneyUtil.divide(totalPrice + currFee, 100)));
		}
		else
		{
			confirmBtn.setBackgroundResource(R.drawable.buttonbg_gray);
			confirmBtn.setPadding(padding, 0, padding, 0);
			confirmBtn.setClickable(false);
			tvTotalPrice.setText(" ¥" + Utils.getMoneyFormat(MoneyUtil.divide(totalPrice, 100)));
		}
	}
	
	private class GoodsAdapter
	        extends
	        BaseAdapter
	{
		private ViewHolder         holder;
		private List<ShoppingCart> data;
		
		public void setData(List<ShoppingCart> data) {
			
			this.data = data;
		}
		
		@Override
		public int getCount() {
			return data.size();
		}
		
		@Override
		public Object getItem(int position) {
			return data.get(position);
		}
		
		@Override
		public long getItemId(int position) {
			return position;
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null)
			{
				holder = new ViewHolder();
				convertView = inflater.inflate(R.layout.goods_detail_item, parent, false);
				holder.name = (TextView) convertView.findViewById(R.id.goods_detail_item_name_tv);
				holder.count = (TextView) convertView.findViewById(R.id.goods_detail_item_original_count_tv);
				holder.price = (TextView) convertView.findViewById(R.id.goods_detail_item_original_price_tv);
				holder.classify = (TextView) convertView.findViewById(R.id.goods_detail_item_classify_tv);
				holder.coverIv = (ImageView) convertView.findViewById(R.id.goods_detail_item_image);
				holder.errorTv = (TextView) convertView.findViewById(R.id.goods_detail_item_error_tv);
				holder.errorRay = (FrameLayout) convertView.findViewById(R.id.goods_detail_item_error_fay);
				convertView.setTag(holder);
			}
			else
			{
				holder = (ViewHolder) convertView.getTag();
			}
			
			holder.name.setText(data.get(position).title);
			holder.count.setText("x" + data.get(position).count);
			holder.price.setText(" ¥" + Utils.getMoneyFormat(MoneyUtil.divide(data.get(position).salePrice - data.get(position).freeMoney, 100)));
			holder.classify.setText(data.get(position).skuPropDetail);
			if (!Utils.isEmpty(data.get(position).picUrl))
			{
				//holder.coverIv.setImageUrl(data.get(position).picUrl);
				PicassoUtil.load(ConfirmOrderActivity.this, data.get(position).picUrl, R.drawable.bg_small_image,holder.coverIv);
			}
			else
			{
				PicassoUtil.load(ConfirmOrderActivity.this, R.drawable.bg_small_image,holder.coverIv);
			}
			
			if (data.get(position).ordersStatus == ShoppingCart.ORDERSTATUS_FAIL && !Utils.isEmpty(data.get(position).errorMsg))
			{
				holder.errorTv.setText(data.get(position).errorMsg);
				holder.errorTv.setVisibility(View.VISIBLE);
				holder.errorRay.setVisibility(View.VISIBLE);
			}
			else
			{
				holder.errorTv.setVisibility(View.GONE);
				holder.errorRay.setVisibility(View.GONE);
			}
			
			return convertView;
		}
	}
	
	private class ViewHolder
	{
		public ImageView coverIv;
		public TextView       name;
		public TextView       price;
		public TextView       count;
		public TextView       classify;
		public TextView       errorTv;
		public FrameLayout    errorRay;
	}
	
	private void clickInvoiceEnterprise() {
		if (!isEnterprise)
		{
			if (!onlyOne && listType !=null && listType.size() == 1)
			{
				tvInvoiceTypeChoose.setText(listType.get(0).getName() + ",");
			}
			invoiceType = INVOICE_TYPE_ENTERPRISE;
			isEnterprise = true;
			isPsersonal = false;
			btnInvoicePersonal.setSelected(false);
			btnInvoiceEnterprise.setSelected(true);
			tvInvoiceChoose.setText(getResources().getString(R.string.confirm_order_bottom_invoice_enterprise));
			invoiceLayEdits.setVisibility(View.VISIBLE);
			edtInvoiceName.setVisibility(View.VISIBLE);
			edtInvoiceNumber.setVisibility(View.VISIBLE);
			listView.post(new Runnable()
			{
				@Override
				public void run() {
					listView.setSelection(ListView.FOCUS_DOWN);
				}
			});
		}
		else
		{
			if (!onlyOne && listType !=null && listType.size() == 1)
			{
				tvInvoiceTypeChoose.setText("");
			}
			invoiceType = INVOICE_TYPE_NONE;
			btnInvoicePersonal.setSelected(false);
			btnInvoiceEnterprise.setSelected(false);
			tvInvoiceChoose.setText("");
			isEnterprise = false;
			isPsersonal = false;
			invoiceLayEdits.setVisibility(View.GONE);
		}
		setDeliverFee();
		setBtn();
	}
	
	private void clickInvoicePersonal() {
		if (!isPsersonal)
		{
			if (!onlyOne && listType !=null && listType.size() == 1)
			{
				tvInvoiceTypeChoose.setText(listType.get(0).getName() + ",");
			}
			invoiceType = INVOICE_TYPE_PERSONAL;
			isPsersonal = true;
			isEnterprise = false;
			btnInvoicePersonal.setSelected(true);
			btnInvoiceEnterprise.setSelected(false);
			tvInvoiceChoose.setText(getResources().getString(R.string.confirm_order_bottom_invoice_personal));
			invoiceLayEdits.setVisibility(View.VISIBLE);
			edtInvoiceName.setVisibility(View.VISIBLE);
			edtInvoiceNumber.setVisibility(View.GONE);
			listView.post(new Runnable()
			{
				@Override
				public void run() {
					listView.setSelection(ListView.FOCUS_DOWN);
				}
			});
		}
		else
		{
			if (!onlyOne && listType !=null && listType.size() == 1)
			{
				tvInvoiceTypeChoose.setText("");
			}
			invoiceType = INVOICE_TYPE_NONE;
			btnInvoicePersonal.setSelected(false);
			btnInvoiceEnterprise.setSelected(false);
			tvInvoiceChoose.setText("");
			isPsersonal = false;
			isEnterprise = false;
			invoiceLayEdits.setVisibility(View.GONE);
		}
		setDeliverFee();
		setBtn();
	}
	
	private void clickInvoice() {
		if (onlyOne)
		{
			invoiceLayContents.setVisibility(View.GONE);
		}
		else
		{
			if (isClose == 0)
			{
				invoiceLayContents.setVisibility(View.VISIBLE);
				isClose = 1;
			}
			else
			{
				invoiceLayContents.setVisibility(View.GONE);
				isClose = 0;
			}
		}
		if (invoiceLayChildren.getVisibility() == View.GONE)
		{
			if (deliverTimeLayChildren.getVisibility() == View.VISIBLE)
			{
				clickDeliver();
			}
			
			invoiceLayChildren.setVisibility(View.VISIBLE);
			switch (invoiceType) {
				case INVOICE_TYPE_NONE:
					invoiceLayEdits.setVisibility(View.GONE);
					break;
				case INVOICE_TYPE_PERSONAL:
					break;
				case INVOICE_TYPE_ENTERPRISE:
					break;
			}
			listView.post(new Runnable()
			{
				@Override
				public void run() {
					listView.setSelection(ListView.FOCUS_DOWN);
				}
			});
			ivInvoiceChoose.setImageResource(R.drawable.change_store_icon);
		}
		else
		{
			invoiceLayChildren.setVisibility(View.GONE);
			ivInvoiceChoose.setImageResource(R.drawable.more_right_bg);
		}
		
	}
	
	private void clickDeliver() {
		if (deliverTimeLayChildren.getVisibility() == View.GONE)
		{
			if (invoiceLayChildren.getVisibility() == View.VISIBLE)
			{
				clickInvoice();
			}
			deliverTimeLayChildren.setVisibility(View.VISIBLE);
			listView.post(new Runnable()
			{
				@Override
				public void run() {
					listView.setSelection(ListView.FOCUS_DOWN);
				}
			});
			ivDeliverChoose.setImageResource(R.drawable.change_store_icon);
		}
		else
		{
			deliverTimeLayChildren.setVisibility(View.GONE);
			ivDeliverChoose.setImageResource(R.drawable.more_right_bg);
		}
		
	}
	
	private void setDeliverTime(int deliverType) {
		switch (deliverType) {
			case DELIVER_TYPE_ALLDAY:
				delivelyTimeType = DELIVER_TYPE_ALLDAY;
				btnDeliverTimeAllDay.setSelected(true);
				btnDeliverTimeWorkDay.setSelected(false);
				btnDeliverTimeHoliDay.setSelected(false);
				tvDeliverChoose.setText(getResources().getString(R.string.confirm_order_bottom_allday));
				break;
			case DELIVER_TYPE_WORKDAY:
				delivelyTimeType = DELIVER_TYPE_WORKDAY;
				btnDeliverTimeAllDay.setSelected(false);
				btnDeliverTimeWorkDay.setSelected(true);
				btnDeliverTimeHoliDay.setSelected(false);
				tvDeliverChoose.setText(getResources().getString(R.string.confirm_order_bottom_workday));
				break;
			case DELIVER_TYPE_HOLIDAY:
				delivelyTimeType = DELIVER_TYPE_HOLIDAY;
				btnDeliverTimeAllDay.setSelected(false);
				btnDeliverTimeWorkDay.setSelected(false);
				btnDeliverTimeHoliDay.setSelected(true);
				tvDeliverChoose.setText(getResources().getString(R.string.confirm_order_bottom_holiday));
				break;
		}
	}
	
	@SuppressLint ("NewApi")
	private void startAnimation(final View v, int endHeight) {
		final LayoutParams params = (LayoutParams) v.getLayoutParams();
		if (android.os.Build.VERSION.SDK_INT > 10)
		{
			ValueAnimator animation = ValueAnimator.ofInt(v.getHeight(), endHeight);
			animation.setDuration(100);
			animation.addUpdateListener(new AnimatorUpdateListener()
			{
				@Override
				public void onAnimationUpdate(ValueAnimator animation) {
					params.height = (Integer.parseInt(animation.getAnimatedValue().toString()));
					v.setLayoutParams(params);
				}
			});
			animation.setInterpolator(new AccelerateInterpolator(0.5f));
			animation.start();
		}
		else
		{
			params.height = endHeight;
			v.setLayoutParams(params);
		}
	}
	
	private void InitOnResultAddressInfo() {
		loadingDialog.show();
		ActionHelp.qryUserDeliveryAddress(context, true, new OnResultAddressHandler());
	}
	
	public void setDeliverFee() {
		if (couponOnly && !wantInvoice())
		{
			tvDeliverFee.setText("免配送费");
			currFee = 0;
		}
		else
		{
			if (fee == 0)
			{
				tvDeliverFee.setText("免配送费");
				currFee = 0;
			}
			else if (fee == -1)
			{
				tvDeliverFee.setText("获取快递费失败,请重新选择收货地址");
				currFee = fee;
			}
			else
			{
				tvDeliverFee.setText(Utils.getMoneyFormat(MoneyUtil.divide(fee, 100)) + "元");
				currFee = fee;
			}
		}
	}
	
	private class OnResultAddressHandler
	        extends
	        ObjectHttpResponseHandler<List<UserAddressInfo>>
	{
		
		@Override
		public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
			loadingDialog.dismiss();
			if (statusCode == 200)
			{
				try
				{
					JSONObject jsonObject = new JSONObject(responseString);
					JSONArray array = jsonObject.getJSONArray("returnObject");
					if (array == null || array.length() == 0)
					{
						topView = noAddressView;
						setBtn();
						setContentView();
					}
				}
				catch (JSONException e)
				{
					Utils.ToastShow(context, "解析错误");
				}
			}
			else if (statusCode < 1000)
			{
				Utils.ToastShow(context, "网络错误");
			}
			else
			{
				Utils.ToastShow(context, "请求出错");
			}
		}
		
		@Override
		public void onSuccess(int statusCode, Header[] headers, List<UserAddressInfo> object, String responseString) {
			addressInfo = object.get(0);
			//			topView = addressView;
			//			tvAddressName.setText(addressInfo.getName());
			//			tvAddressPhone.setText(addressInfo.getPhone());
			//			tvAdress.setText("收货地址：" + addressInfo.getProvinceName() + addressInfo.getCityName() + addressInfo.getAreaName() + addressInfo.getDetailAddress());
			//			provinceID = addressInfo.getProviceId();
			//			System.out.println(provinceID + "");
			//			InitDiliverMoney();
			//			setBtn();
			//			setContentView();
			loadingDialog.dismiss();
			
			changeAddress(addressInfo);
		}
		
		@Override
		public Type getType() {
			return new TypeToken<List<UserAddressInfo>>()
			{
			}.getType();
		}
		
	}
	
}
